<?php
namespace app\api\controller;
use app\common\controller\Common;
use app\common\exception\ParameterException;
use think\Request;
use app\common\logic\Shop as ShopLogic;
use app\common\logic\Collection as CollectionLogic;
use think\Loader;

/**
 * @title 店铺模块接口
 * @description 接口说明
 * @group 接口分组
 *
 */
class Shop extends Common
{
    /**
     * @title 获取商店分类
     * @description 接口说明
     * @author WCJ
     * @url /api/shop/getshoptypelist
     * @method POST
     * @param name:topid type:int require:0 default:1 other: desc:分类顶级id
     *
     * @return id: 分类ID
     * @return name: 分类名称
     * @return pictureid: 分类图标
     *
     */

    public function getshoptypelist(Request $request)
    {
        if($request->isPost()) {
            $topid = $request->post('topid') ? $request->post('topid') : 0;
            $validate = Loader::validate("Common");
                if (!$validate->scene("common")->check(['id' => $topid])) {
                    return ['errorCode' => 404, 'code' => 201, 'msg' => $validate->getError()];
                    die();
                }
            $shoplogic = new ShopLogic();
            $data = $shoplogic->getshoptype($topid);
            return ["code" => 200, "msg" => "成功", "data" => $data];
        }

    }


    /**
     * @title 获取地域信息
     * @description 接口说明
     * @author WCJ
     * @url /api/shop/getarealist
     * @method POST
     * @param name:topid type:int require:0 default:1 other: desc:父级默认100000
     * @param name:id type:int require:0 default:1 other: desc:父级默认100000
     *
     * @return id: 分类ID
     * @return name: 分类名称
     * @return pictureid: 分类图标
     *
     */

    public function getarealist(Request $request)
    {
        if($request->isPost()) {
            $topid = $request->post('topid') ? $request->post('topid') :100000;
            $id = $request->post('id') ? $request->post('id') :0;
            $validate = Loader::validate("Common");
            if (!$validate->scene("common")->check(['id' => $topid])) {
                return ['code' => 201, 'msg' => $validate->getError()];
                die();
            }
            $shoplogic = new ShopLogic();
            $data = $shoplogic->getarealist($topid,$id);
            return ["code" => 200, "msg" => "成功", "data" => $data];
        }

    }


    /**
     * @title 获取店铺列表
     * @description 接口说明
     * @author WCJ
     * @url /api/shop/getshoplist
     * @method POST
     *
     * @param name:typeid type:int require:0 default:1 other: desc:分类id
     * @param name:area_id type:int require:0 default:1 other: desc:地域id
     * @param name:lat type:int require:0 default:1 other: desc: 你的纬度
     * @param name:lon type:int require:0 default:1 other: desc: 你的精度
     * @param name:raidus type:int require:0 default:1 other: desc: 你的raidus单位米
     * @param name:start type:int require:0 default:1 other: desc:起止数
     * @param name:num type:int require:0 default:20 other: desc:个数
     *
     * @return id: 店铺ID
     * @return name: 店铺名称
     * @return address:店铺地址
     * @return areaname:地区名
     * @return thumb:缩略图
     * @return push:地区名
     * @return lat:纬度
     * @return lng:经度
     * @return tel:电话
     * @return stars:星星
     * @return consumption:人均消费
     * @return consnumber:消费人数
     *
     */

    public function getshoplist(Request $request)
    {
        if($request->isPost()) {
            $typeid = $request->post('typeid');
            $lat = $request->post('lat');
            $lon = $request->post('lon');
            $area_id=$request->post('area_id');
            $raidus = $request->post('raidus')?$request->post('raidus'):1000000;
            $start = $request->post('start') ? $request->post('start') : 1;
            $num = $request->post('num') ? $request->post('num') : 20;

            $validate = Loader::validate("Common");
            if (!$validate->scene("nearby")->check(['lat' => $lat,'lon' => $lon,'raidus' => $raidus])) {
                throw new ParameterException(['errorCode' => 404, 'msg' => $validate->getError(),'code' => 201]);
                die();
            }


            if (!$validate->scene("common")->check(['id' => $typeid])) {
                throw new ParameterException(['errorCode' => 404, 'msg' => $validate->getError(),'code' => 201]);
                die();
            }

            if (!$validate->scene("aid")->check(['aid' => $area_id])) {
                throw new ParameterException(['errorCode' => 404, 'msg' => $validate->getError(),'code' => 201]);
                die();
            }

            $shoplogic = new ShopLogic();

            $data = $shoplogic->get_shoplist($lat,$lon,$raidus, $typeid,$start, $num,$area_id);

            return ["code" => 200, "msg" => "成功", "data" => $data];
        }

    }

    /**
     * @title 获取店铺详情
     * @description 接口说明
     * @author WCJ
     * @url /api/shop/getshopinfo
     * @method POST
     * @param name:shopid type:int require:0 default:1 other: desc:店铺id
     * @param name:lat type:int require:0 default:1 other: desc: 你的纬度
     * @param name:lon type:int require:0 default:1 other: desc: 你的精度
     *
     * @return id: 店铺ID
     * @return name: 店铺名称
     * @return address:店铺地址
     * @return lat:纬度
     * @return lng:经度
     * @return typeid:店铺分类id
     * @return picurl:缩略图
     * @return shophours:经营时间
     * @return picture_array:店铺banner组图
     * @return environ_array:店铺环境组图
     * @return tel:电话
     * @return stars:星级
     *
     */

    public function getshopinfo(Request $request)
    {
        if($request->isPost()) {
            $shopid = $request->post('shopid');
            $lat = $request->post('lat');
            $lon = $request->post('lon');
            $validate = Loader::validate("Common");
            if (!$validate->scene("nearby")->check(['lat' => $lat,'lon' => $lon,'raidus' => 0])) {
                throw new ParameterException(['errorCode' => 404, 'msg' => $validate->getError(),'code' => 201]);
                die();
            }

            if (!$validate->scene("shopid")->check(['shopid' => $shopid])) {
                throw  new ParameterException(['errorCode' => 404, 'msg' => $validate->getError(),'code' => 201]);
                die();
            }
            $shoplogic = new ShopLogic();
            $data = $shoplogic->getshopinfo($shopid,$lat,$lon);
            $pjdata = $shoplogic->get_praise($shopid);

            $collectionlogic=new CollectionLogic();
            $collect_count=$collectionlogic->getCollectionListByShopidCount($shopid);

            return ["code" => 200, "msg" => "成功", "data" => $data,"pjdata"=>$pjdata,"collect_count"=>$collect_count];
        }

    }

    /**
     * @title 获取店铺项目
     * @description 接口说明
     * @author WCJ
     * @url /api/shop/getshopitem
     * @method POST
     * @param name:shopid type:int require:0 default:1 other: desc:店铺id
     * @param name:start type:int require:0 default:0 other: desc:开始数
     * @param name:num type:int require:0 default:20 other: desc:个数
     *
     * @return id: 店铺ID
     * @return cid: 类别ID
     * @return name:项目名称
     * @return content:该项目下的产品
     * @return money:价格
     * @return soldnum:已售量
     *
     */

    public function getshopitem(Request $request){
        if($request->isPost()) {
            $shopid = $request->post('shopid');
            $validate = Loader::validate("Common");
            if (!$validate->scene("common")->check(['id' => $shopid])) {
                throw  new ParameterException(['errorCode' => 404, 'msg' => $validate->getError(),'code' => 201]);
                die();
            }
            $start = $request->post('start') ? $request->post('start') : 1;
            $num = $request->post('num') ? $request->post('num') : 20;
            $shoplogic = new ShopLogic();
            $data = $shoplogic->getshopitem($shopid, $start, $num);
            return ["code" => 200, "msg" => "成功", "data" => $data];
        }

    }


    /**
     * @title 获取技师列表
     * @description 接口说明
     * @author WCJ
     * @url /api/shop/getshopteach
     * @method POST
     * @param name:shopid type:int require:0 default:1 other: desc:店铺id
     *
     * @return id: 技师ID
     * @return age: 年龄
     * @return name:技师姓名
     * @return sex:性别
     * @return picurl:照片
     * @return position:职位
     * @return goodat:擅长
     *
     */

    public function getshopteach(Request $request){
        if($request->isPost()) {
            $shopid = $request->post('shopid');
            $validate = Loader::validate("Common");
            if (!$validate->scene("common")->check(['id' => $shopid])) {
                throw  new ParameterException(['errorCode' => 404, 'msg' => $validate->getError(),'code' => 201]);
                die();
            }

            $start = $request->post('start') ? $request->post('start') : 1;
            $num = $request->post('num') ? $request->post('num') : 20;
            $shoplogic = new ShopLogic();
            $data = $shoplogic->getshopteach($shopid, $start, $num);
            return ["code" => 200, "msg" => "成功", "data" => $data];
        }

    }


    /**
     * @title 获取店铺评价
     * @description 接口说明
     * @author WCJ
     * @url /api/shop/get_shop_praise
     * @method POST
     * @param name:shopid type:int require:0 default:1 other: desc:店铺id
     * @param name:start type:int require:0 default:0 other: desc:开始数
     * @param name:num type:int require:0 default:20 other: desc:个数
     *
     * @return data:数据
     *
     */

    public function get_shop_praise(Request $request){
        if($request->isPost()) {
            $shopid = $request->post('shopid');
            $validate = Loader::validate("Common");
            if (!$validate->scene("common")->check(['id' => $shopid])) {
                throw  new ParameterException(['errorCode' => 404, 'msg' => $validate->getError(),'code' => 201]);
                die();
            }
            $start = $request->post('start') ? $request->post('start') : 1;
            $num = $request->post('num') ? $request->post('num') : 20;
            $shoplogic = new ShopLogic();
            $data = $shoplogic->get_praise($shopid, $start, $num);
            return ["code" => 200, "msg" => "成功", "data" => $data];
        }

    }






}